﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CodeBase
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = { 49, 38, 65, 97, 76, 13, 27 };
            var sortedArray = SortMethod.QuickSort(array, 0, array.Length - 1);
            for (int i = 0; i < sortedArray.Length; i++)
            {
                Console.WriteLine(sortedArray[i]);
            }
            //Console.ReadLine();
            Console.ReadKey();
        }


        static void ThreadLocalTest()
        {
            // Thread-Local variable that yields a name for a thread
            ThreadLocal<string> ThreadName = new ThreadLocal<string>(() =>
            {
                return "Thread" + Thread.CurrentThread.ManagedThreadId;
            });

            // Action that prints out ThreadName for the current thread
            Action action = () =>
            {
                // If ThreadName.IsValueCreated is true, it means that we are not the
                // first action to run on this thread.
                bool repeat = ThreadName.IsValueCreated;

                Console.WriteLine("ThreadName = {0} {1}", ThreadName.Value, repeat ? "(repeat)" : "");
            };

            // Launch eight of them.  On 4 cores or less, you should see some repeat ThreadNames
            Parallel.Invoke(action, action, action, action, action, action, action, action);

            // Dispose when you are done
            ThreadName.Dispose();
        }


        static void Action调用()
        {
            Action action = () => { Console.WriteLine("dddd"); };
            AsyncCallback callback = new AsyncCallback(ProcessDnsInformation);
            action.BeginInvoke(callback, new { ddd = "caonima" });

            //ThreadPool.QueueUserWorkItem()
        }


        static void ProcessDnsInformation(IAsyncResult result)
        {
            Console.WriteLine(result.AsyncState);
            Console.WriteLine(result.IsCompleted);
            Console.WriteLine(result.CompletedSynchronously);
        }

    }
}
